<?php 
//?fill_db=3000&cats=1|3&tags=tag1|tag2|tag3
function fill_db_with_posts(){
	if( !isset($_GET['fill_db']) ) return;
	$limit = (int) $_GET['fill_db'];
	if(!$limit || !is_numeric($limit)) $limit=50;
	$cats = $_GET['cats'] ? $_GET['cats'] : '1';
	$tags = $_GET['tags'] ? $_GET['tags'] : '';
	for($i=1; $i<=$limit; $i++){
		$rand = (string) rand(1,99999);
		$content = '';
		for($g=0; $g<30; $g++)
			$content .= "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum accumsan: $rand . ";
		$post_date = get_random('2009|2011').'-0'.rand(1,4).'-'.rand(10,30).' 23:25:59';
		$post = array(
		   'comment_status' => get_random('closed|open')
		  ,'ping_status' 	=> get_random('closed|open')
		  ,'post_category'	=> array( get_random($cats) )
		  ,'post_title' 	=> "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum accumsan.  $rand"
		  ,'post_content' 	=> $content
		  ,'post_date' 		=> $post_date
		  ,'tags_input' 	=> get_random($tags)
		  ,'post_status' 	=> 'publish'
		);  

		$postid = wp_insert_post( $post );
		flush();
	}
	return;
}

function fill_db_with_comments(){
	if( !isset($_GET['fill_db_comments']) ) return;
	$limit = (int) $_GET['fill_db_comments'];
	if(!$limit || !is_numeric($limit)) $limit=50;

	global $wpdb;
	$IDs = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status='publish' AND post_type='realestate' ORDER BY rand() LIMIT 150", ARRAY_A);
	foreach($IDs as $v) $IDsfix[] = $v['ID'];
	for($i=1; $i<=$limit; $i++){
		$rand = (string) rand(1,99999);

		$content = '';
		for($g=0; $g<10; $g++)
			$content .= "комментарий: $rand . ";
		$post_date = get_random('2010|2011').'-0'.rand(1,3).'-'.rand(10,30).' 23:25:59';

		$post = array(
			'comment_post_ID' => array_rand($IDsfix)
			,'comment_author' => 'commentator name'
			,'comment_author_email' => 'devlab@wordpressor.com.ua'
			,'comment_author_url' => ''
			,'comment_content' => $content
			,'comment_author_IP' => '127.0.0.1'
			,'comment_agent' => 'Opera 10.0'
			,'comment_date' => $post_date
			,'comment_approved' => 1
		);  

		$postid = wp_insert_comment( $post );
		flush();
	}
	return;
}

function get_random($data=''){
	$arg = explode('|', $data);
	if(count($arg)==1)
		return $arg[0];
	$n = rand(0, count($arg)-1);
	return $arg[$n];
}
fill_db_with_posts();
fill_db_with_comments();


?>